const db = wx.cloud.database()
const questionList = db.collection('user_information')
const {
	$Message
} = require('../../dist/base/index');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		log_time: false,
		notice_input: false,
		notice_id: '',
		notice_value: '',
		user_notice: [],
		notice_show: false,
		phone_search: '',
		now_time: '',
		table_confirm: false,
		table_dialog: false,
		table_success: false,
		all_succeed: false,
		checked: false,
		come_in: '👈🏽',
		showLeft: false,
		tabs_active: '',
		name: '',
		canIUse: wx.canIUse('button.open-type.getUserInfo'),
		//信息
		user_head_title: '',
		user_head_url: '',
		// 用户身份控制
		dialogs:false,

		identity: '',
		identity_show: '',
		user_identity: '',
		user_identity_select: ['学生', '教师', ],
		// 步骤条及信息上传状态
		current: '',
		// 注册表单
		user_name: '',
		user_id: '',
		user_class: '',
		user_pronal: '',
		user_phone: '',
		user_grade: '',
		user_sex: '',
		user_age: '',
		user_family: '',
		user_idcard: '',
		// 用户工作单位表单
		user_job_teacher: '',
		user_job_firm: '',
		user_job_type: '',
		user_job_posts: '',
		user_job_add: '',
		user_job_name: '',
		user_job_phone: '',
		user_job_state: '',
		user_job_Salary: '',
		//文件上传

		agree_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		outside_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		safe_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		lodging_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		autonomic_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		inspect_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		agreement_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		scheme_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		report_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},
		identify_table: {
			filePath: '',
			filename: '',
			filestate: '',
			filecreattime: '',
			fileid: '',
			id: '',
		},

		// 实习日志
		work_time: '',
		work_info: '',

		visible2: false,
		//小程序没有refs，所以只能用动态布尔值控制关闭
		toggle: false,
		toggle2: false,
		actions: [{
			name: ' 删除',
			color: '#fff',
			fontsize: '20',
			width: 100,
			icon: 'delete',
			background: '#ed3f14'
		}],
		// 表单选择器
		index: '',
		user_pronal_select: ['物联网应用技术', '计算机应用技术', '数字媒体技术', '广播影视节目制作'],
		user_grade_select: ['2020级', '2021级', '2022级', '2023级'],
		user_sex_select: ['男', '女'],
		user_class_select: ['1班', '2班', '3班', '4班', '5班', '6班', '7班', '8班', '9班', '10班', '11班', '12班', ],
		user_job_teacher_select: ['张有泽', '李娇', '朱小云', '白梅', '司马碧荣', '欧新宇'],
		region: ['云南省', '昆明市', ''],
		user_job_type_select: ['信息传输、软件和信息技术服务业', '教育', '卫生和社会工作', '农、林、牧、渔业', '采矿业', '制造业', '电力、热力、燃气及水生产和供应业', '建筑业', '批发和零售业', '交通运输、仓储和邮政业', '住宿和餐饮业', '金融业', '房地产业', '租赁和商务服务业', '科学研究和技术服务业', '水利、环境和公共设施管理业', '居民服务、管理和其他服务业', '文化、体育和娱乐业', '公共管理、社会保障和社会组织', '国际组织'],
		customItem: '',
		//提交按钮
		loading: false,
		dialog_buttom: [{
			text: '取消'
		}, {
			text: '确定'
		}],
		dialog_buttom1: [{
			text: '修改时间'
		}, {
			text: '完成填报'
		}],
		// 教师端
		// 存放学生信息
		studentinfo: [],
		//修改个人信息确认按钮
		edit: false,
		// 上传日志按钮
		camar: false,
		camarsub: [{
			type: 'primary',
			className: '',
			text: '发表',
			value: 1,
			buttontap: 'userlogsub'
		}],
		//用户上传日志
		content: '',
		files: [],
		cloudfiles: [],
		logmap: '',
		logtime: '',
		// 日志渲染
		userlog: [],
		img_view: false,
		img_view_index: '',
		// 日志喜欢
		like: [],
		// 日志评论
		bottom: '',
		comment_id: '',
		comment_type: '',
		comment_placeholder: '',
		comment_name: '',
		comment_input: false,
		comment: [{
			comment_type: '',
			first_person: '',
			second_person: '',
			comment_content: ''
		}],
		about: false,
		help: false,
		phone: false,
		// 搜索
		inputShowed: false,
		inputVal: "",
		search: '',
		//通讯录
		phone_list: [],
		edit_button:[
			{
				text: '更新信息',
				type: 'primary',
                className: '',
                value: 0
			},
		]
	},

	handleSuccess: function () {
		$Message({
			content: '实习信息上报成功!',
			type: 'success'
		})
	},
	agree_null: function () {
		$Message({
			content: '请勾选“我同意《用户协议》和《隐私政策》”',
			type: 'error'
		})
	},
	zhuseSuccess: function () {
		$Message({
			content: '注册成功!',
			type: 'success'
		})
	},
	// 全局成功
	success: function () {
		$Message({
			content: '成功!',
			type: 'success'
		})
	},

	tableerror: function () {
		$Message({
			content: '表单不能为空!',
			type: 'error'
		})
	},
	/**
	 * 生命周期函数--------------------------------1-------------------------------监听页面加载
	 */
	async onLoad() {
		this.singleCountDown(); //页面加载时就启动定时器
		this.setData({
			search: this.search.bind(this),
			selectFile: this.selectFile.bind(this),
			uplaodFile: this.uplaodFile.bind(this)
		})
		//加载页面第一件事，获取用户openid
		this.getOpenid();
		let openId = wx.getStorageSync('openId')
		// console.log(openId)
		// 查询数据库中是否有用户数据
		let identity = this.data.identity
		let res = await db.collection("user_information").doc(openId).get()
			.then(res => {
				this.setData({
					user_head_url: res.data.user_head_url,
					user_head_title: res.data.user_head_title,
					user_identity: res.data.user_identity,
					identity_show: res.data.identity_show,
					identity: res.data.user_identity,
					user_name: res.data.user_name,
					user_id: res.data.user_id,
					user_pronal: res.data.user_pronal,
					user_phone: res.data.user_phone,
					user_grade: res.data.user_grade,
					user_class: res.data.user_class,
					user_sex: res.data.user_sex,
					user_age: res.data.user_age,
					user_family: res.data.user_family,
					user_idcard: res.data.user_idcard,
					user_job_teacher: res.data.user_job_teacher,
					user_job_firm: res.data.user_job_firm,
					user_job_type: res.data.user_job_type,
					user_job_posts: res.data.user_job_posts,
					user_job_add: res.data.user_job_add,
					user_job_name: res.data.user_job_name,
					user_job_phone: res.data.user_job_phone,
					user_job_state: res.data.user_job_state,
					user_job_Salary: res.data.user_job_Salary,
					current: res.data.current,
				})
			})

		let user_identity = this.data.user_identity
		let agree_table = this.data.agree_table
		let user_job_teacher = this.data.user_name
		let user_name = this.data.user_job_teacher
		let current = this.data.current
		if (user_identity == 0) {
			db.collection("user_exercitation_table").doc(openId).get()
				.then(res => {
					//将文件存入缓存
					wx.setStorageSync('file', res.data)
					// console.log( res.data)
					this.setData({
						['agree_table.filePath']: res.data.agree_table.filePath,
						['agree_table.filename']: res.data.agree_table.filename,
						['agree_table.filecreattime']: res.data.agree_table.filecreattime,
						['agree_table.filestate']: res.data.agree_table.filestate,
						['agree_table.id']: res.data.agree_table.id,

						['outside_table.filePath']: res.data.outside_table.filePath,
						['outside_table.filename']: res.data.outside_table.filename,
						['outside_table.filecreattime']: res.data.outside_table.filecreattime,
						['outside_table.filestate']: res.data.outside_table.filestate,
						['outside_table.id']: res.data.outside_table.id,

						['safe_table.filePath']: res.data.safe_table.filePath,
						['safe_table.filename']: res.data.safe_table.filename,
						['safe_table.filecreattime']: res.data.safe_table.filecreattime,
						['safe_table.filestate']: res.data.safe_table.filestate,
						['safe_table.id']: res.data.safe_table.id,

						['lodging_table.filePath']: res.data.lodging_table.filePath,
						['lodging_table.filename']: res.data.lodging_table.filename,
						['lodging_table.filecreattime']: res.data.lodging_table.filecreattime,
						['lodging_table.filestate']: res.data.lodging_table.filestate,
						['lodging_table.id']: res.data.lodging_table.id,

						['autonomic_table.filePath']: res.data.autonomic_table.filePath,
						['autonomic_table.filename']: res.data.autonomic_table.filename,
						['autonomic_table.filecreattime']: res.data.autonomic_table.filecreattime,
						['autonomic_table.filestate']: res.data.autonomic_table.filestate,
						['autonomic_table.id']: res.data.autonomic_table.id,

						['inspect_table.filePath']: res.data.inspect_table.filePath,
						['inspect_table.filename']: res.data.inspect_table.filename,
						['inspect_table.filecreattime']: res.data.inspect_table.filecreattime,
						['inspect_table.filestate']: res.data.inspect_table.filestate,
						['inspect_table.id']: res.data.inspect_table.id,

						['agreement_table.filePath']: res.data.agreement_table.filePath,
						['agreement_table.filename']: res.data.agreement_table.filename,
						['agreement_table.filecreattime']: res.data.agreement_table.filecreattime,
						['agreement_table.filestate']: res.data.agreement_table.filestate,
						['agreement_table.id']: res.data.agreement_table.id,

						['report_table.filePath']: res.data.report_table.filePath,
						['report_table.filename']: res.data.report_table.filename,
						['report_table.filecreattime']: res.data.report_table.filecreattime,
						['report_table.filestate']: res.data.report_table.filestate,
						['report_table.id']: res.data.report_table.id,

						['identify_table.filePath']: res.data.identify_table.filePath,
						['identify_table.filename']: res.data.identify_table.filename,
						['identify_table.filecreattime']: res.data.identify_table.filecreattime,
						['identify_table.filestate']: res.data.identify_table.filestate,
						['identify_table.id']: res.data.identify_table.id,


						['scheme_table.filePath']: res.data.scheme_table.filePath,
						['scheme_table.filename']: res.data.scheme_table.filename,
						['scheme_table.filecreattime']: res.data.scheme_table.filecreattime,
						['scheme_table.filestate']: res.data.scheme_table.filestate,
						['scheme_table.id']: res.data.scheme_table.id,
					})



					// 判断是否实习材料审批通过，通过么显示跳转到日志填报的按钮
					let currents = res.data.agree_table.filestate + res.data.outside_table.filestate + res.data.safe_table.filestate + res.data.lodging_table.filestate + res.data.autonomic_table.filestate + res.data.inspect_table.filestate + res.data.agreement_table.filestate + res.data.scheme_table.filestate
					// console.log(currents)
					if (currents == 8) {
						this.setData({
							table_success: true,
						})

					}

					// 判断是否全部审批通过，通过么显示完成按钮
					let all_succeed = res.data.report_table.filestate + res.data.identify_table.filestate
					//   console.log(all_succeed)
					if (all_succeed == 2) {
						this.setData({
							all_succeed: true
						})

					}


				})








			// db.collection("user_information").where({
			// 			user_job_teacher: user_name,
			// 			current: '00'
			// 		}).get()
			// 		.then(res => {
			// 			this.setData({
			// 				usercheck: res.data
			// 			})
			// 			let usercheck = this.data.usercheck
			// 			// console.log('审核列表', usercheck)
			// 		})




			if (current == '2' || current == '5') {
				db.collection("userlog").orderBy('timestamp', 'desc').get()
					.then(res => {
						// console.log('日志渲染数据', res.data)
						this.setData({
							userlog: res.data
						})

					})

			}
		

			db.collection("select_info").get()
			.then(res => {
				// console.log('选择数据', res.data[0].user_class_select)
				this.setData({
					user_pronal_select:res.data[0].user_pronal_select,
					user_grade_select:res.data[0].user_grade_select,
					user_class_select :res.data[0].user_class_select,
					user_job_teacher_select:res.data[0].user_job_teacher_select,
					user_job_type_select :res.data[0].user_job_type_select,
				})

			})


		}

		// ////////////////////////////////////////
		//老师身份需要渲染的数据
		if (user_identity == 1) {
			db.collection("user_information").doc(openId).get()
				.then(res => {
					this.setData({
						user_head_url: res.data.user_head_url,
						user_head_title: res.data.user_head_title,
						user_identity: res.data.user_identity,
						identity_show: res.data.identity_show,
						identity: res.data.user_identity,
						user_name: res.data.user_name,
					})
				})

			let user_name = this.data.user_name

			db.collection("user_exercitation_table").where({
					user_job_teacher: user_name
				}).get()
				.then(res => {
					this.setData({
						studentinfo: res.data
					})
					let studentinfo = this.data.studentinfo
				})


			db.collection("userlog").orderBy('timestamp', 'desc').get()
				.then(res => {
					console.log('日志渲染数据', res.data)
					this.setData({
						userlog: res.data,
						likestate: []
					})
				})




			db.collection("user_information").where({
					user_job_teacher: user_name,
					current: '00'
				}).get()
				.then(res => {
					this.setData({
						usercheck: res.data
					})
					let usercheck = this.data.usercheck
					// console.log('审核列表', usercheck)
				})






		}

		var timestamps = Date.parse(new Date()); //获取当前时间戳
		var creattimes = this.formatDates(timestamps) //转换时间戳
		this.setData({
			now_time: creattimes
		})

		this.log_time_panduan()

	},

	// 用户身份更新
	user_identity: function () {
		let user_identity_select = this.data.user_identity_select
		let index = this.data.index
		let identity_show = this.identity_show
		this.setData({
			identity_show: user_identity_select[index],
			identity: index
		})

	},

	tapDialogButton() {
		this.setData({
			dialog: false
		})
	},

	bindGetUserInfo: function (e) {
		console.log(e.detail.userInfo)
	},


	// 用户头像选择
	onChooseAvatar(e) {
		// console.log(e.detail.avatarUrl)
		var newDateTime = Date.parse(new Date())
		wx.cloud.uploadFile({
				cloudPath: 'userlog_img/' + '用户头像' + newDateTime + '-' + '.png', // 上传至云端的路径
				filePath: e.detail.avatarUrl // 小程序临时文件路径，需结合小程序相关 API 获取
			})
			.then((res) => {
				this.setData({
					user_head_url: res.fileID

				})
			});
	},

// 用户点击授权登录事件，初始化用户信息
	zhuce: function () {
		let user_head_title = this.data.user_head_title
		let user_head_url = this.data.user_head_url
		let user_name= this.data.user_name
		let identity_show = this.data.identity_show
		let checked = this.data.checked
		if (user_name==''|| identity_show == '' || user_head_title == '' || user_head_url == '') {
			wx.showToast({
				icon:'error',
			  title: '注册信息不完整',
			})
		} else {
			if (checked != true) {
				console.log(123)
				this.agree_null()
			} else {
				// 上传用户信息到数据库
				let openId = wx.getStorageSync('openId')
				let identity = this.data.identity
				let identity_show = this.data.identity_show

				db.collection("user_information").doc(openId).set({
					data: {
						user_identity: identity,
						user_head_title: user_head_title,
						user_head_url: user_head_url,
						identity_show: identity_show,
						user_name: user_name,
						user_id: '',
						user_pronal: '',
						user_phone: '',
						user_grade: '',
						user_class: '',
						user_sex: '',
						user_age: '',
						user_family: '',
						user_idcard: '',
						user_job_teacher: '',
						user_job_firm: '',
						user_job_type: '',
						user_job_posts: '',
						user_job_add: '',
						user_job_name: '',
						user_job_phone: '',
						user_job_state: '',
						user_job_Salary: '',
						current: '0',
					},
				})

				db.collection("user_exercitation_table").doc(openId).set({
					data: {
						agree_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						outside_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						safe_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						lodging_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						autonomic_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						inspect_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						agreement_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						scheme_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						report_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
						identify_table: {
							filePath: '',
							filename: '',
							filestate: '',
							filecreattime: '',
							fileid: '',
							id: '',
						},
					},
				})


				setTimeout(() => {
					this.onLoad()
				}, 3000)
				this.zhuseSuccess()
			}

		}
	},
	

	// 用户信息上传列表框点击事件
	user_pronal: function () {
		let user_pronal_select = this.data.user_pronal_select
		let index = this.data.index
		let user_pronal = this.data.user_pronal
		this.setData({
			user_pronal: user_pronal_select[index]
		})
	},
	user_grade: function () {
		let user_grade_select = this.data.user_grade_select
		let index = this.data.index
		let user_grade = this.data.user_grade
		this.setData({
			user_grade: user_grade_select[index]
		})
	},

	user_class: function () {
		let user_class_select = this.data.user_class_select
		let index = this.data.index
		let user_class = this.data.user_class
		this.setData({
			user_class: user_class_select[index]
		})
	},

	user_sex: function () {
		let user_sex_select = this.data.user_sex_select
		let index = this.data.index
		let user_sex = this.data.user_sex
		this.setData({
			user_sex: user_sex_select[index]
		})
	},

	user_job_teacher: function () {
		let user_job_teacher_select = this.data.user_job_teacher_select
		let index = this.data.index
		let user_job_teacher = this.data.user_job_teacher
		this.setData({
			user_job_teacher: user_job_teacher_select[index]
		})
	},

	user_job_type: function () {
		let user_job_type_select = this.data.user_job_type_select
		let index = this.data.index
		let user_job_type = this.data.user_job_type
		this.setData({
			user_job_type: user_job_type_select[index]
		})
	},

	user_age: function () {
		let index = this.data.index
		let user_age = this.data.user_age
		this.setData({
			user_age: index
		})
	},
	user_job_add: function (e) {
		let region = e.detail.value
		this.setData({
			user_job_add: region[0] + region[1] + region[2]
		})

	},
	user_job_state: function () {
		let index = this.data.index
		let user_job_state = this.data.user_job_state
		this.setData({
			user_job_state: index
		})
	},


	table_confirm: function () {
		this.setData({
			table_confirm: true
		})

	},
	table_confirms: function (e) {
		if (e.detail.index == 0) {
			this.setData({
				table_confirm: false
			})

		}

		if (e.detail.index == 1) {
			this.sub_table();
			this.setData({
				table_confirm: false
			})
		}
	},
	//提交按钮事件
	sub_table() {
		//1.加载状态
		let loading = this.data.loading
		this.setData({
			loading: true
		})

		let openId = wx.getStorageSync('openId')
		let user_name = this.data.user_name
		let user_id = this.data.user_id
		let user_pronal = this.data.user_pronal
		let user_phone = this.data.user_phone
		let user_grade = this.data.user_grade
		let user_class = this.data.user_class
		let user_sex = this.data.user_sex
		let user_age = this.data.user_age
		let user_family = this.data.user_family
		let user_idcard = this.data.user_idcard
		let user_job_teacher = this.data.user_job_teacher
		let user_job_firm = this.data.user_job_firm
		let user_job_type = this.data.user_job_type
		let user_job_posts = this.data.user_job_posts
		let user_job_add = this.data.user_job_add
		let user_job_name = this.data.user_job_name
		let user_job_phone = this.data.user_job_phone
		let user_job_state = this.data.user_job_state
		let user_job_Salary = this.data.user_job_Salary
		// 2.验证表单
		if (
			user_name == '' ||
			user_id == '' ||
			user_pronal == '' ||
			user_phone == '' ||
			user_grade == '' ||
			user_class == '' ||
			user_sex == '' ||
			user_age == '' ||
			user_family == '' ||
			user_idcard == '' ||
			user_job_teacher == '' ||
			user_job_firm == '' ||
			user_job_type == '' ||
			user_job_posts == '' ||
			user_job_add == '' ||
			user_job_name == '' ||
			user_job_phone == '' ||
			user_job_state == '' ||
			user_job_Salary == ''
		) {

			this.setData({
				loading: false,
			})
			this.tableerror()

		} else {


			db.collection("user_information").doc(openId).update({
				data: {
					user_name: user_name,
					user_id: user_id,
					user_pronal: user_pronal,
					user_phone: user_phone,
					user_grade: user_grade,
					user_class: user_class,
					user_sex: user_sex,
					user_age: user_age,
					user_family: user_family,
					user_idcard: user_idcard,
					user_job_teacher: user_job_teacher,
					user_job_firm: user_job_firm,
					user_job_type: user_job_type,
					user_job_posts: user_job_posts,
					user_job_add: user_job_add,
					user_job_name: user_job_name,
					user_job_phone: user_job_phone,
					user_job_state: user_job_state,
					user_job_Salary: user_job_Salary,
					current: '00'
				},
			})

			db.collection("user_exercitation_table").doc(openId).update({
				data: {
					user_name: user_name,
					user_job_teacher: user_job_teacher,
					user_job_firm: user_job_firm,
				},
			})

			// 7.刷新页面
			this.setData({
				loading: false,
				current: '00'
			})

			// 6.成功提示
			this.handleSuccess()

		}

	},
	//更新用户信息--------------------------------------------------------------------------------
	edit_tap(e) {
		this.update_userinfo()
    },
	update_userinfo() {
		//1.加载状态
		let loading = this.data.loading
		this.setData({
			loading: true
		})
		let openId = wx.getStorageSync('openId')
		let user_head_url = this.data.user_head_url
		let user_head_title = this.data.user_head_title
		let user_job_teacher = this.data.user_job_teacher
		let user_job_firm = this.data.user_job_firm
		let user_job_type = this.data.user_job_type
		let user_job_posts = this.data.user_job_posts
		let user_job_add = this.data.user_job_add
		let user_job_name = this.data.user_job_name
		let user_job_phone = this.data.user_job_phone
		let user_job_state = this.data.user_job_state
		let user_job_Salary = this.data.user_job_Salary
		// 2.验证表单
		if (
			user_head_url == '' ||
			user_head_title == '' ||
			user_job_teacher == '' ||
			user_job_firm == '' ||
			user_job_type == '' ||
			user_job_posts == '' ||
			user_job_add == '' ||
			user_job_name == '' ||
			user_job_phone == '' ||
			user_job_state == '' ||
			user_job_Salary == ''
		) {
			wx.showToast({
				title: '表单不能为空',
				icon: "none",
				duration: 2000,
				mask: true
			})
			this.setData({
				loading: false
			})
		} else {


			// 3.错误提示
			// 4.上传表单


			db.collection("user_information").doc(openId).update({
				data: {
					user_head_url: user_head_url,
					user_head_title: user_head_title,
					user_job_teacher: user_job_teacher,
					user_job_firm: user_job_firm,
					user_job_type: user_job_type,
					user_job_posts: user_job_posts,
					user_job_add: user_job_add,
					user_job_name: user_job_name,
					user_job_phone: user_job_phone,
					user_job_state: user_job_state,
					user_job_Salary: user_job_Salary,
				},
			})

			db.collection("user_exercitation_table").doc(openId).update({
				data: {
					user_job_teacher: user_job_teacher,
					user_job_firm: user_job_firm,
				},
			})
			// 7.刷新页面
			setTimeout(() => {
				// wx.showToast({
				// 	title: '更新成功',
				// 	icon: "none",
				// 	duration: 2000,
				// 	mask: true
				// })
				this.success();
				this.onLoad()

			}, 2000)

			this.setData({
				loading: false,
				edit: false

			})


		}

	},


	//老师信息更新
	update_teacherinfo() {
		//1.加载状态
		let loading = this.data.loading
		this.setData({
			loading: true
		})
		let openId = wx.getStorageSync('openId')
		let user_head_url = this.data.user_head_url
		let user_head_title = this.data.user_head_title
		// 2.验证表单
		if (
			user_head_url == '' ||
			user_head_title == ''

		) {
			wx.showToast({
				title: '表单不能为空',
				icon: "none",
				duration: 2000,
				mask: true
			})
			this.setData({
				loading: false
			})
		} else {


			// 3.错误提示
			// 4.上传表单


			db.collection("user_information").doc(openId).update({
				data: {
					user_head_url: user_head_url,
					user_head_title: user_head_title,

				},
			})

			// 7.刷新页面
			setTimeout(() => {

				this.success();

				// wx.showToast({
				// 	title: '更新成功',
				// 	icon: "none",
				// 	duration: 2000,
				// 	mask: true
				// })

			}, 2000)

			this.setData({
				loading: false,
				edit: false

			})


		}
	},

// 用户文件上传
	add: function (e) {
		var id = e.target.id
		var _that = this;
		wx.chooseMessageFile({ // 会话中选择文件API
			count: 1, // 可选文件个数
			type: 'file', // 文件类型
			success(res) { // 选择成功后的回调函数
				// console.log(res)
				wx.setStorageSync('filepath', res.tempFiles[0].path)
				var size = res.tempFiles[0].size; // 文件大小
				var filename = res.tempFiles[0].name; // 文件名
				var timestamp = Date.parse(new Date()); //获取当前时间戳
				var creattime = _that.formatDate(timestamp) //转换时间戳
				// console.log(creattime)

				if (size > 10194301) { // 判断文件大小不能大于4M
					wx.showToast({ // 弹框提示
						title: '文件大小不能超过10MB！',
						icon: "none",
						duration: 2000,
						mask: true
					})
				} else if (filename.indexOf('.pdf') == -1) { // 判断文件格式必须为pdf
					wx.showToast({
						title: '文件格式必须为PDF！',
						icon: "none",
						duration: 2000,
						mask: true
					})
				} else {
					let openId = wx.getStorageSync('openId')

					if (id == 0) {

						_that.setData({
							['agree_table.filePath']: res.tempFiles[0].path,
							['agree_table.filename']: filename,
							['agree_table.filecreattime']: creattime,
							['agree_table.filestate']: 9,
							['agree_table.id']: e.currentTarget.id,

						})




						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['agree_table.fileid']: res.fileID
							})

							let fileid = _that.data.agree_table.fileid
							// console.log(fileid)
						})

						setTimeout(() => {
							let agree_table = _that.data.agree_table

							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									agree_table: agree_table,
								}
							})
						}, 10000)
						//上传文件函数

					} else if (id == 1) {

						_that.setData({
							['outside_table.filePath']: res.tempFiles[0].path,
							['outside_table.filename']: filename,
							['outside_table.filecreattime']: creattime,
							['outside_table.filestate']: 9,
							['outside_table.id']: e.currentTarget.id
						})

						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['outside_table.fileid']: res.fileID
							})

							let fileid = _that.data.outside_table.fileid
							// console.log(fileid)
						})

						setTimeout(() => {
							let outside_table = _that.data.outside_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									outside_table: outside_table,
								}
							})

						}, 10000)
					} else if (id == 2) {


						_that.setData({

							['safe_table.filePath']: res.tempFiles[0].path,
							['safe_table.filename']: filename,
							['safe_table.filecreattime']: creattime,
							['safe_table.filestate']: 9,
							['safe_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['safe_table.fileid']: res.fileID
							})

							let fileid = _that.data.safe_table.fileid
							// console.log(fileid)
						})

						setTimeout(() => {


							let safe_table = _that.data.safe_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									safe_table: safe_table,
								}
							})

						}, 10000)
					} else if (id == 3) {


						_that.setData({
							['lodging_table.filePath']: res.tempFiles[0].path,
							['lodging_table.filename']: filename,
							['lodging_table.filecreattime']: creattime,
							['lodging_table.filestate']: 9,
							['lodging_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['lodging_table.fileid']: res.fileID
							})

							let fileid = _that.data.lodging_table.fileid
							// console.log(fileid)
						})

						setTimeout(() => {

							let lodging_table = _that.data.lodging_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									lodging_table: lodging_table,
								}
							})

						}, 10000)
					} else if (id == 4) {


						_that.setData({
							['autonomic_table.filePath']: res.tempFiles[0].path,
							['autonomic_table.filename']: filename,
							['autonomic_table.filecreattime']: creattime,
							['autonomic_table.filestate']: 9,
							['autonomic_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['autonomic_table.fileid']: res.fileID
							})


						})

						setTimeout(() => {

							let autonomic_table = _that.data.autonomic_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									autonomic_table: autonomic_table,
								}
							})

						}, 10000)
					} else if (id == 5) {


						_that.setData({
							['inspect_table.filePath']: res.tempFiles[0].path,
							['inspect_table.filename']: filename,
							['inspect_table.filecreattime']: creattime,
							['inspect_table.filestate']: 9,
							['inspect_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['inspect_table.fileid']: res.fileID
							})


						})

						setTimeout(() => {

							let inspect_table = _that.data.inspect_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									inspect_table: inspect_table,
								}
							})

						}, 10000)

					} else if (id == 6) {


						_that.setData({
							['agreement_table.filePath']: res.tempFiles[0].path,
							['agreement_table.filename']: filename,
							['agreement_table.filecreattime']: creattime,
							['agreement_table.filestate']: 9,
							['agreement_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['agreement_table.fileid']: res.fileID
							})


						})

						setTimeout(() => {

							let agreement_table = _that.data.agreement_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									agreement_table: agreement_table,
								}
							})

						}, 10000)
					} else if (id == 7) {


						_that.setData({
							['scheme_table.filePath']: res.tempFiles[0].path,
							['scheme_table.filename']: filename,
							['scheme_table.filecreattime']: creattime,
							['scheme_table.filestate']: 9,
							['scheme_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['scheme_table.fileid']: res.fileID
							})


						})

						setTimeout(() => {

							let scheme_table = _that.data.scheme_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									scheme_table: scheme_table,
								}
							})

						}, 10000)
					} else if (id == 8) {


						_that.setData({
							['report_table.filePath']: res.tempFiles[0].path,
							['report_table.filename']: filename,
							['report_table.filecreattime']: creattime,
							['report_table.filestate']: 9,
							['report_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['report_table.fileid']: res.fileID
							})


						})

						setTimeout(() => {

							let report_table = _that.data.report_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									report_table: report_table,
								}
							})

						}, 10000)
					} else if (id == 9) {


						_that.setData({
							['identify_table.filePath']: res.tempFiles[0].path,
							['identify_table.filename']: filename,
							['identify_table.filecreattime']: creattime,
							['identify_table.filestate']: 9,
							['identify_table.id']: e.currentTarget.id
						})
						wx.cloud.uploadFile({
							cloudPath: 'userfile_FDF/' + filename, // 对象存储路径，根路径直接填文件名，文件夹例子 test/文件名，不要 / 开头
							filePath: res.tempFiles[0].path, // 微信本地文件，通过选择图片，聊天文件等接口获取
							config: {
								env: 'cloud1-6g5s31628d8e621b' // 需要替换成自己的微信云托管环境ID
							}
						}).then(res => {
							// console.log(res.fileID)
							_that.setData({
								['identify_table.fileid']: res.fileID
							})


						})

						setTimeout(() => {

							let identify_table = _that.data.identify_table
							db.collection("user_exercitation_table").doc(openId).update({
								data: {
									identify_table: identify_table,
								}
							})

						}, 10000)
					}





				}



			},




		})
		// let filePath = this.data.filePath
		// let filename = this.data.filename
		// let filestate = this.data.filestate
		// let id = this.data.id


	},


	//预览PDF函数
	view: function (e) {
		let id = e.target.id

		if (id == 'agree_table') {
			let agree_table = this.data.agree_table.filePath
			wx.openDocument({
				filePath: agree_table, //要打开的文件路径
			})
		} else if (id == 'agreement_table') {
			let agreement_table = this.data.agreement_table.filePath
			wx.openDocument({
				filePath: agreement_table,
			})
		} else if (id == 'autonomic_table') {
			let autonomic_table = this.data.autonomic_table.filePath
			wx.openDocument({
				filePath: autonomic_table,
			})
		} else if (id == 'inspect_table') {
			let inspect_table = this.data.inspect_table.filePath
			wx.openDocument({
				filePath: inspect_table
			})
		} else if (id == 'lodging_table') {
			let lodging_table = this.data.lodging_table.filePath
			wx.openDocument({
				filePath: lodging_table,
			})
		} else if (id == 'outside_table') {
			let outside_table = this.data.outside_table.filePath
			wx.openDocument({
				filePath: outside_table,
			})
		} else if (id == 'report_table') {
			let report_table = this.data.report_table.filePath
			wx.openDocument({
				filePath: report_table,
			})
		} else if (id == 'safe_table') {
			let safe_table = this.data.safe_table.filePath
			wx.openDocument({
				filePath: safe_table,
			})
		} else if (id == 'scheme_table') {
			let scheme_table = this.data.scheme_table.filePath
			wx.openDocument({
				filePath: scheme_table,
			})
		} else if (id == 'report_table') {
			let report_table = this.data.report_table.filePath
			wx.openDocument({
				filePath: report_table,
			})
		} else if (id == 'identify_table') {
			let identify_table = this.data.identify_table.filePath
			wx.openDocument({
				filePath: identify_table,
			})
		}


	},

	// 教师审核端函数
	// 预览函数
	inspect: function (e) {
		// console.log(e.target.id)
		wx.cloud.downloadFile({
			fileID: e.target.id, // 对象存储文件ID，从上传文件接口或者控制台获取
			success: res => {


				let filepath = res.tempFilePath
				wx.openDocument({
					filePath: filepath,
					fail: function (res) {
						// console.log(res)
					}
				})
			},
			fail: err => {
				console.error(err)
			}
		})







	},
	tabs_active({
		detail
	}) {
		this.setData({
			tabs_active: detail.key
		});
	},
	
	// 通过函数
	pass: function (e) {
		let id = e.target.id
		var arr = id.split(".");
		var _openId = arr[0];
		var table = arr[1];
		var index = arr[2];
		var state = 'studentinfo' + '[' + index + ']' + table + '.filestate'
		var filestate = table + '.filestate'
		// console.log(state)
		db.collection("user_exercitation_table").doc(_openId).update({
			data: {
				[filestate]: 1
			}
		})
		this.setData({
			[state]: 1
		})
		this.success();

		// wx.showToast({
		// 	title: '已通过！',
		// 	icon: "none",
		// 	duration: 1000,
		// 	mask: true
		// })

	},
	// 打回函数
	back: function (e) {
		let id = e.target.id
		var arr = id.split(".");
		var _openId = arr[0];
		var table = arr[1];
		var index = arr[2];
		var state = 'studentinfo' + '[' + index + ']' + table + '.filestate'
		var filestate = table + '.filestate'
		// console.log(arr)
		// console.log(state)
		db.collection("user_exercitation_table").doc(_openId).update({
			data: {
				[filestate]: 2
			}
		})
		this.setData({
			[state]: 2
		})

		wx.showToast({
			title: '已打回！',
			icon: "none",
			duration: 1000,
			mask: true
		})
	},
	//半弹窗-------------------------------------
	open: function () {
		this.setData({
			edit: true,
			showLeft: false,

		})
	},
	camars: function () {
		this.setData({
			camar: true
		})

	},
	echarts: function () {
		wx.navigateTo({
			url: '../echarts/echarts',
		})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		// 分享朋友圈
		wx.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		})

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		this.onRefresh();
		this.onLoad();
	},
	onRefresh: function () {
		//导航条加载动画
		wx.showNavigationBarLoading()
		setTimeout(function () {
			wx.hideNavigationBarLoading();
			//停止下拉刷新
			wx.stopPullDownRefresh();

		}, 2000)
		this.success();
	},


	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */

	onShareAppMessage() {
		return {
			title: '爆肝半年打造的小程序是什么样的？',
			path: '/pages/index/index', //用户点开后的默认页面，我默认为首页
			imageUrl: "../../images/index.png", //自定义图片的地址
			success(res) {

				this.success();

				// wx.showToast({
				// 	title: '分享成功!',
				// 	icon: "success",
				// 	duration: 2000,
				// 	mask: true
				// })
			}
		}
	},


	getOpenid() {
		wx.cloud.callFunction({
			name: 'getopenid',
			complete: res => {
				//将获取到的openid存入缓存里
				// console.log(res.result.openid)
				wx.setStorageSync('openId', res.result.openid);
			}
		})
	},

	// 时间戳转换函数
	formatDate: function (inputTime) {
		var date = new Date(inputTime);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? ('0' + m) : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		var h = date.getHours();
		h = h < 10 ? ('0' + h) : h;
		var minute = date.getMinutes();
		var second = date.getSeconds();
		minute = minute < 10 ? ('0' + minute) : minute;
		second = second < 10 ? ('0' + second) : second;
		return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
	},
	formatDates: function (inputTime) {
		var date = new Date(inputTime);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? ('0' + m) : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		var h = date.getHours();
		h = h < 10 ? ('0' + h) : h;
		var minute = date.getMinutes();
		var second = date.getSeconds();
		minute = minute < 10 ? ('0' + minute) : minute;
		second = second < 10 ? ('0' + second) : second;
		return y + '-' + m + '-' + d;
	},


	chooseImage: function (e) {

		var that = this;
		wx.chooseImage({
			sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			success: function (res) {
				// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
				that.setData({
					files: that.data.files.tempFilePaths
				});
			}


		})


	},
	previewImage: function (e) {
		wx.previewImage({
			current: e.currentTarget.id, // 当前显示图片的http链接
			urls: this.data.files // 需要预览的图片http链接列表
		})
	},
	selectFile(files) {
		this.data.files = this.data.files.concat(files.tempFilePaths);
		let filess = this.data.files
		// console.log('files', filess.length)
		// 返回false可以阻止某次文件上传
	},
	uplaodFile(files) {
		// console.log('upload files', files.tempFilePaths)
		// 文件上传的函数，返回一个promise
		return new Promise((resolve, reject) => {
			resolve({
				"urls": files.tempFilePaths
			})
		})
		this.userlogsuccess()
	},
	uploadError(e) {
		// console.log('upload error', e.detail)
	},
	uploadSuccess(e) {
		// console.log('upload success', e.detail)
	},
	// 删除图片函数
	uploaddelete(e) {
		this.data.files.splice(e.detail.index, 1);
		let filess = this.data.files
		// console.log('files', filess)
	},
	async post() {
		wx.showLoading({
			title: '上传中...',
		})
		let files = this.data.files
		// console.log('文件本地地址',files[index])
		var newDateTime = Date.parse(new Date())
		var logtime = this.formatDate(newDateTime) //转换时间戳


		for (var i = 0; i < files.length; i++) {

			let filepath = files[i]
			await wx.cloud.uploadFile({
					cloudPath: 'userlog_img/' + newDateTime + '-' + i + '.png', // 上传至云端的路径
					filePath: filepath // 小程序临时文件路径，需结合小程序相关 API 获取
				})
				.then((res) => {
					this.setData({
						logtime: logtime
					})
					this.data.cloudfiles = this.data.cloudfiles.concat(res.fileID);


				});
		}
		//****************** 连接数据库上传全部信息*******************************************/
		let openId = wx.getStorageSync('openId')
		let content = this.data.content
		let cloudfiles = this.data.cloudfiles
		let user_head_title = this.data.user_head_title
		let user_head_url = this.data.user_head_url
		let user_name = this.data.user_name
		db.collection('userlog').add({
				data: {
					user_name: user_name,
					user_head_title: user_head_title,
					user_head_url: user_head_url,
					content: content,
					files: cloudfiles,
					logtime: logtime,
					logmap: 'NULL',
					timestamp: newDateTime

				},
			}).then(res => {
				wx.hideLoading()

				// wx.showToast({
				// 	title: '发表成功!',
				// 	icon: "success",
				// 	duration: 2000,
				// 	mask: true
				// })
				this.success();

				this.setData({
					camar: false
				})
				this.setData({
					files: [],
					cloudfiles: []
				})

			})
			.catch(res => {
				wx.showToast({
					title: '发表失败!',
					icon: "woang",
					duration: 2000,
					mask: true
				})

			})
	},
	getInputValue: function () {
		let content = this.data.content
	},


	tellophone: function (e) {
		// console.log(e)
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.id,
		})
	},


	// 用户信息通过函数
	userinfopass: function (e) {
		// console.log(e)
		let id = e.target.id
		db.collection("user_information").doc(id).update({
			data: {
				current: 1
			}
		})
		setTimeout(() => {
			this.onLoad()
		}, 3000)

		this.success();
		// wx.showToast({
		// 	title: '已通过！',
		// 	icon: "none",
		// 	duration: 1000,
		// 	mask: true
		// })


	},

	// 用户信息打回函数

	notice_bindconfirm: function () {
		this.setData({
			notice_input: false
		})
		let notice_value = this.data.notice_value
		let notice_id = this.data.notice_id
		var newDateTime = Date.parse(new Date())
		var notice_time = this.formatDate(newDateTime) //转换时间戳
		// console.log(notice_time,notice_value,notice_id)

		db.collection("user_information").doc(notice_id).update({
			data: {
				current: '000'
			}
		})
		db.collection("notice").add({
			data: {
				user_notice: notice_id,
				notice_title: '用户信息审核通知',
				notice_text: notice_value,
				notice_time: notice_time
			}
		})
		setTimeout(() => {
			this.onLoad()
		}, 3000)
		wx.showToast({
			title: '已打回！',
			icon: "none",
			duration: 1000,
			mask: true
		})
	},
	userinfoback: function (e) {
		this.setData({
			notice_value: '',
			notice_input: true,
			notice_id: e.target.id
		})

	},

	galleryhide() {
		// console.log('component hide')
		setTimeout(() => {
			// console.log('component show')
			this.setData({
				gallery: true
			})
		}, 1000)
	},

	// 用户点击喜欢函数

	like: function (e) {
		// console.log(e)
		let user_head_title = this.data.user_head_title
		let openId = wx.getStorageSync('openId')
		const _ = db.command
		db.collection("userlog").doc(e.currentTarget.id).update({
			data: {
				likelist: _.push([{
					openId: openId,
					user_head_title: user_head_title,
					likestate: true
				}]),
			}
		})
		setTimeout(() => {
			this.onLoad()
		}, 10)
	},

	likes: function (e) {
		// console.log(e)
		let user_head_title = this.data.user_head_title
		let openId = wx.getStorageSync('openId')
		const _ = db.command
		db.collection("userlog").doc(e.currentTarget.id).update({
			data: {
				likelist: _.pull({
					openId: openId
				}),
			}
		})
		setTimeout(() => {
			this.onLoad()
		}, 10)
	},

	toggleLeft() {
		// console.log("点击")
		this.setData({
			showLeft: !this.data.showLeft
		});
	},
	share() {
		this.setData({
			showLeft: false,
		})
	},
	about() {
		this.setData({
			about: true,
			showLeft: false,
		})
	},
	help() {
		this.setData({
			help: true,
			showLeft: false,
		})
	},
	phone() {
		this.setData({
			phone: true,
		})
		db.collection("user_information").get()
			.then(res => {
				this.setData({
					phone_list: res.data
				})
				let phone_list = this.data.phone_list
				// console.log('hone', phone_list)
			})
	},
	user_agree() {
		wx.navigateTo({
			url: '../protocol/protocol',
		})
	},
	user_link() {
		// console.log(4)
		wx.navigateTo({
			url: '../privacy/privacy',
		})

	},
	checkboxChange: function (e) {
		let val = e.detail.value
		if (val.length > 0) {
			this.setData({
				checked: true,
			})
			//   let checked = this.data.checked
			//   console.log(checked)
		} else {
			this.setData({
				checked: false,
			})
			//   let checked = this.data.checked
			//   console.log(checked)
		}
	},



	//搜索
	search: function (value) {
		this.setData({
			phone_search: ""
		})
		let phone_list = this.data.phone_list
		for (let i = 0; i < phone_list.length; i++) {
			if (value == phone_list[i].user_name) {
				this.setData({
					phone_search: phone_list[i]
				})
			}
		}

		return new Promise((resolve, reject) => {})
	},
	selectResult: function (e) {
		// console.log('select result', e)
	},

	//画廊
	img_view: function (e) {
		this.setData({
			img_view: true,
			img_view: [],
			img_view_index: ''
		})
		// console.log('dianjibig',e)
		var arr = e.currentTarget.id.split(",");
		// console.log('显示的照片',arr)
		this.setData({
			img_view: true,
			img_view: arr,
			img_view_index: e.target.id
		})
	},
	comment_bindblur: function () {
		this.setData({
			comment_input: false
		})
	},
	notice_bindblur: function () {
		this.setData({
			notice_input: false
		})
	},
	comment_bindconfirm: function () {
		this.setData({
			comment_input: false
		})
		let comment_value = this.data.comment_value
		let user_name = this.data.user_name
		let comment_name = this.data.comment_name
		let comment_id = this.data.comment_id
		let comment_type = this.data.comment_type
		const _ = db.command
		// console.log(user_name, comment_value, comment_name, comment_id)
		db.collection("userlog").doc(comment_id).update({
			data: {
				comment: _.push([{
					comment_type: comment_type,
					first_person: user_name,
					second_person: comment_name,
					comment_content: comment_value
				}]),
			}
		})
		setTimeout(() => {
			this.onLoad()
		}, 10)



	},
	comment: function (e) {
		this.setData({
			comment_input: true,
			comment_type: '0',
			comment_id: e.currentTarget.id,
			comment_placeholder: '评论'
		})
	},
	comment_hui: function (e) {
		// console.log(e)
		this.setData({
			comment_type: '1',
			comment_input: true,
			comment_id: e.currentTarget.id,
			comment_name: e.target.id,
			// comment_id:
			comment_placeholder: '回复' + e.target.id
		})
	},
	//获取焦点
	onbindfocus(e) {
		// console.log(e)
		this.setData({
			top: e.detail.height,
		})
	},
	all_succeed: function () {
		let openId = wx.getStorageSync('openId')

		db.collection("user_information").doc(openId).update({
			data: {
				current: 5,
			}

		})

		wx.navigateTo({
			url: '../success/success',
		})
		setTimeout(() => {
			this.onLoad()
		}, 100)

	},
	table_success: function () {
		let openId = wx.getStorageSync('openId')
		this.setData({
			table_dialog: true
		})
		db.collection("user_information").doc(openId).update({
			data: {
				current: 2,
			}
		})
	},
	tapDialogButton: function (e) {
		// console.log(e)
		if (e.detail.index == 0) {
			this.setData({
				table_dialog: false
			})

		} else if (e.detail.index == 1) {
			wx.navigateTo({
				url: '../tableccess/tableccess',
			})
		}
	},

	log_time: function (e) {
		// console.log(e.detail.index)
		if (e.detail.index == 1) {
			this.setData({
				log_time: false
			})
			let openId = wx.getStorageSync('openId')
			db.collection("user_information").doc(openId).update({
				data: {
					current: 3
				},
			})
			setTimeout(() => {
				this.onLoad()
			}, 100)

		} else if (e.detail.index == 0) {
			this.setData({
				log_time: false
			})
			this.open();
		}
	},


	//倒计时
	singleCountDown: function () {
		var that = this;
		var time = 0;
		var obj = {};
		var endTime = new Date(that.data.user_job_state.replace(/-/g, "/")).getTime(); //结束时间时间戳

		var currentTime = new Date().getTime(); //当前时间时间戳
		time = (endTime - currentTime) / 1000;
		// console.log('time',time)
		// 如果活动未结束
		if (time > 0) {
			var d = parseInt(time / 60 / 60 / 24); // 天
			d = d < 10 ? '0' + d : d;
			var h = parseInt(time / 60 / 60 % 24); //时
			h = h < 10 ? '0' + h : h;
			var m = parseInt(time / 60 % 60); // 分
			m = m < 10 ? '0' + m : m;
			var s = parseInt(time % 60); // 当前的秒
			s = s < 10 ? '0' + s : s;
			obj = {
				d: d,
				h: h,
				m: m,
				s: s
			}
		} else { //活动已结束
			obj = {
				d: "00",
				h: "00",
				m: "00",
				s: "00"
			}


			clearTimeout(that.data.timeIntervalSingle); //清除定时器
		}
		var timeIntervalSingle = setTimeout(that.singleCountDown, 1000);
		that.setData({
			txtTime: obj,
			timeIntervalSingle,
		})
	},

	log_time_panduan: function () {
		var that = this;
		var time = 0;
		var endTime = new Date(that.data.user_job_state.replace(/-/g, "/")).getTime(); //结束时间时间戳
		var currentTime = new Date().getTime(); //当前时间时间戳
		time = (endTime - currentTime) / 1000;
		// console.log('time',time)
		// 如果活动未结束
		if (time < 0) { //活动已结束

			that.setData({
				log_time: true
			})
		}
	},
	notice: function () {
		this.setData({
			notice_show: true
		})
		let openId = wx.getStorageSync('openId')
		db.collection("notice").where({
				user_notice: openId
			}).orderBy('notice_time', 'desc').get()
			.then(res => {
				// console.log(res.data)
				this.setData({
					user_notice: res.data
				})
			})
	},
	tiaozhaun:function(){

		wx.navigateToMiniProgram({
			appId: 'wxecb6ec955663becd',
			path: 'pages/index/index',
			extraData: {
			  foo: 'bar'
			},
			envVersion: 'develop',
			success(res) {
			  // 打开成功
			}
		  })
	},
	explain:function(){
		db.collection("users_manual").get()
		.then(res => {
			// console.log(res.data[0]._id)

				wx.cloud.downloadFile({
			fileID: res.data[0].users_manual, // 对象存储文件ID，从上传文件接口或者控制台获取
			success: res => {
				// console.log(res)
				let filepath = res.tempFilePath
				wx.openDocument({
					filePath: filepath,
					fail: function (res) {
						// console.log('res',res)
					}
				})
			},
			fail: err => {
				console.error(err)
			}
		})
		})
	}

})